<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="充值用户账号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.payType" placeholder="支付类型" :value="dataForm.payType">
          <el-option key="1"  label="充值余额" value="1"> </el-option>
          <el-option key="0"  label="充值现金券" value="0"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.userType" placeholder="用户类型" :value="dataForm.userType">
          <el-option
            v-for="type in typeNameList"
            :key="type.val"
            :label="type.label"
            :value="type.val">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
				<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
			  </el-date-picker>
			</el-form-item>
			<el-form-item label="">
				<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
			  </el-date-picker>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.keywords = ''
          dataForm.payType = ''
          dataForm.userType = ''
          dataForm.startTime = ''
          dataForm.endTime = ''
          getDataList()">重置</el-button>
        <el-button icon="el-icon-download" type="primary" @click="excel()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="addTime"
        header-align="center"
        align="center"
        label="充值时间">
      </el-table-column>
      <el-table-column
        prop="pdAmount"
        header-align="center"
        align="center"
        label="支付金额">
        <template slot-scope="scope">
          <span v-if="scope.row.pdAmount != null">￥ {{scope.row.pdAmount}}</span>
          <span v-if="scope.row.pdAmount == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="充值用户账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="充值用户名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="充值用户类型">
      </el-table-column>
      <el-table-column
        prop="payType"
        header-align="center"
        align="center"
        label="支付类型">
      </el-table-column>
      <el-table-column
        prop="integral"
        header-align="center"
        align="center"
        label="充值现金券">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import {typeName, typeNameList} from '@/utils/memberType'
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        payType: '',
        userType: '',
        startTime: '',
        endTime: ''
      },
      typeNameList: typeNameList,
      memberType: typeName,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: []
    }
  },
  components: {
  },
  activated () {
    this.getDataList()
  },
  methods: {
      // 获取数据列表
    getDataList (getUserType) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/user/recharge'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex - 1,
          'limit': this.pageSize,
          'keywords': this.dataForm.keywords,
          'userType': getUserType,
          'payType': this.dataForm.payType,
          'startTime': this.dataForm.startTime,
          'endTime': this.dataForm.endTime
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
          console.log(this.dataList)
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
      // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
      // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
      // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    excel () {
      window.location.href = this.$http.adornUrl(`/user/rechargeExcel?token=${this.$cookie.get('token')}&payType=${this.dataForm.payType}&userType=${this.dataForm.userType}&startTime=${this.dataForm.startTime}&endTime=${this.dataForm.endTime}&keywords=${this.dataForm.keywords}`)
    }
  }
}
</script>
<style>
  .characters{
    width:300px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
